<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<body>
<%
	String id = request.getParameter("id");	

	ArrayList<String> list = new ArrayList<String>();
	Cookie[] arr = request.getCookies();
	
	String newArr = "";
	if (arr != null) {
		for (Cookie c : arr) {
			if ("goodId".equals(c.getName())) {
				String[] cId = c.getValue().split(",");

				for(int i = 0; i < cId.length ; i++ ){
					list.add(cId[i]);
				}
				
				for(int j = 0;j < list.size() - 1; j++){
					if(id.equals(list.get(j))){
						list.remove(j);
					}
					Object[] lists = list.toArray();
					newArr += lists[j]+",";
				}
				
				System.out.println(newArr+"== newArr");
				Cookie cookie = new Cookie("goodId",newArr);
				if("".equals(newArr)){
					cookie.setMaxAge(0);
				}else{
					cookie.setMaxAge(60*60*24);
				}
				response.addCookie(cookie);
				out.write("<script>location.href='showCart.jsp'</script>");
			}
		}
	}

%>



</body>
</html>